package inet.app.vod.view;

import inet.app.vod.activity.R;
import inet.app.vod.listeners.VideoSummaryListener;
import inet.app.vod.object.MovieModel;
import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.inet.app.framework.bitmap.UniversalImageUtil;
import com.inet.app.framework.util.hardware.ConvertUtil;

public class VideoSummaryView extends BaseRelativeLayout {

	public RelativeLayout mMainLayout;
	public ImageView mBackGround;
	public TextView mNumView;
	public TextView mTitleTextView;
	private Context mContext;

	public VideoSummaryView(Context context) {

		super(context);
		initLayout(context, R.layout.view_video_summary);
		mMainLayout = (RelativeLayout) findViewById(R.id.main_layout);
		mBackGround = (ImageView) findViewById(R.id.background_imgview);
		mNumView = (TextView) findViewById(R.id.num_view_text);
		mTitleTextView = (TextView) findViewById(R.id.title_textview);
		mContext = context;
	}

	/**
	 * Generate UI from movie model
	 * 
	 * @param model
	 */
	public void generateUIfromModel(final MovieModel model,
			final VideoSummaryListener listener) {

		mNumView.setText(String.valueOf(model.getNumView()));
		mTitleTextView.setText(model.getTitle());
		UniversalImageUtil.getInstance(mContext).displayImage(model.getImg(),
				mBackGround);

		this.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				listener.onClick(model);
			}
		});
	}

	/**
	 * set height for VideoSummaryView
	 * 
	 * @param height
	 *            height with dp
	 */
	public void setHeightDp(int height) {
		float heightPx = ConvertUtil.convertDpToPixel(mContext, height);
		this.getLayoutParams().height = (int) heightPx;
	}

	/**
	 * set width for VideoSummaryView
	 * 
	 * @param width
	 *            width with dp
	 */
	public void setWidthDp(int width) {
		float widthPx = ConvertUtil.convertDpToPixel(mContext, width);
		this.getLayoutParams().height = (int) widthPx;
	}

}
